package com.kgcx.schedule.controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kgcx.core.utils.JsonUtil;
import com.kgcx.core.utils.LngLatUtil;
import com.kgcx.schedule.service.DriverStateService;
import com.kgcx.schedule.service.ScheduleOrderBookService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author 袁进勇
 *
 */
@Api(value = "工具接口", tags = "工具接口")
@RestController
@RequestMapping(value = "/v1/schedule/tools")
public class ScheduleToolsController extends SuperController {

    @RequestMapping(value = "/calculateDistance", method = RequestMethod.POST)
    @ApiOperation(value = "计算2个坐标的距离(米)", httpMethod = "POST", notes = "")
    public String calculateDistance(@ApiParam(name = "lng1", value = "经度1", required = true) @RequestParam Double lng1, //
            @ApiParam(name = "lat1", value = "维度1", required = true) @RequestParam Double lat1, //
            @ApiParam(name = "lng2", value = "经度2", required = true) @RequestParam Double lng2, //
            @ApiParam(name = "lat2", value = "维度2", required = true) @RequestParam Double lat2 //
    ) {
        return LngLatUtil.getDistance(lat1, lng1, lat2, lng2).intValue() + "米";
    }

    @RequestMapping(value = "/formatJson", method = RequestMethod.POST)
    @ApiOperation(value = "格式化JSON", httpMethod = "POST", notes = "")
    public String formatJson(
            @ApiParam(name = "json", value = "未格式化的JSON字符串", required = true) @RequestBody String jsonStr //
    ) {
        return JsonUtil.toPrettyString(JsonUtil.toMap(jsonStr));
    }

    @RequestMapping(value = "/driverStateSwitch", method = RequestMethod.POST)
    @ApiOperation(value = "司机状态、车位调派重构，切换开关", httpMethod = "POST", notes = "")
    public void driverStateSwitch(
            @ApiParam(name = "switch", value = "开关", required = true) @RequestBody Boolean driverStateSwitch //
    ) {
        DriverStateService.SWITCH = driverStateSwitch;
    }

    @RequestMapping(value = "/bookOrderSwitch", method = RequestMethod.POST)
    @ApiOperation(value = "是否启用预约单功能，切换开关", httpMethod = "POST", notes = "")
    public void bookOrderSwitch(
            @ApiParam(name = "switch", value = "开关", required = true) @RequestBody Boolean bookOrderSwitch //
    ) {
        ScheduleOrderBookService.SWITCH = bookOrderSwitch;
    }
}
